﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Collections;

namespace Catering.Catering_Page.Caipin
{
    public partial class shiputzypj_Manage_Regth : UserIsNull
    {
        Catering.View_Operaction_Common voc = new View_Operaction_Common();
        Catering.View_Operaction.Caipin_Manage_Operaction cmo = new Catering.View_Operaction.Caipin_Manage_Operaction();
        public string str_All = string.Empty;
        public string str_1 = string.Empty;
        public string str_2 = string.Empty;
        public string str_3 = string.Empty;
        public string str_4 = string.Empty;
        public string str_5 = string.Empty;
        public string str_6 = string.Empty;
        public string str_7 = string.Empty;
        public Int32 RadionID = 5;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //string str_backurl = Session["backurl"] as string;
                // //添加开始
                //if (Session["radioID"] != null)
                //{
                //    string str = Session["radioID"] as string;
                //    str = str.Replace("'", "").Replace("'", "").Trim();
                //    Boolean bl = Int32.TryParse(str, out RadionID);
                //    //添加结束

                //    if (str_backurl != null)
                //    {
                //        string[] strs = str_backurl.Replace("'", "").Split(new char[] { '|', ' ' });
                //        if ((Session["Group"] as string).Length > 0)
                //        {
                //            div_Group.Visible = true;
                //            div_Person.Visible = false;
                //            Getload_Group(strs);
                //            voc.DropDownListDataBind_zhou(this.Dr_zhoulist, str_backurl);
                //            GetDataList();
                //        }
                //        else if ((Session["Personal"] as string).Length > 0)
                //        {
                //            div_Group.Visible = false;
                //            div_Person.Visible = true;
                //            Getload_Personal(strs);
                //            voc.DropDownListDataBind_zhou(this.dr_zhous, str_backurl);
                //            GetDataList();
                //        }
                //    }
                //    else
                //    {
                        if( Session["GroupID"] !=null && Session["ClassID"] !=null)
                        {
                        ViewState["caipu"] = cmo.GetShipuList(Session["GroupID"].ToString(), Session["ClassID"].ToString(), RadionID);
                        }


                //    }
                //}
                //else
                //{
                //    if (Session["GroupID"] != null && Session["ClassID"] != null)
                //    {
                //      //  ViewState["caipu"] = cmo.GetShipuList(Session["GroupID"].ToString(), Session["ClassID"].ToString(), RadionID);
                //    }


                //}
            }
        }
        public List<Catering_Model.E_Recipes> GetShipuList(string strAeraID, string strClass, Int32 RadionID)
        {
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            Catering_Rules.T_Recipes crgc = new Catering_Rules.T_Recipes();
            //"AreaID=" + strAeraID + "  and ClassIDs=" + strClass
            ;
            List<Catering_Model.E_Recipes> list = crgc.GetModelList("");
            return list;
        }
       
        //public string GetShipuList(string strAeraID, string strClass, Int32 RadionID)
        //{
        //    System.Text.StringBuilder sb = new System.Text.StringBuilder();
        //    Catering_Rules.Recipes crgc = new Catering_Rules.Recipes();
        //    //"AreaID=" + strAeraID + "  and ClassIDs=" + strClass
        //    ;
        //    List<Catering_Model.Recipes> list = crgc.GetModelList("");
        //    //foreach (Catering_Model.Recipes cmr in list)
        //    //{
        //    //    int Number = 0;
        //    //    sb.Append("<tr onclick=\"shipu_list_Select(" + cmr.id + ")\">");
        //    //    sb.Append(" <td class=\"xh_td\">" + cmr.id + "</td>");
        //    //    sb.Append(" <td> " + cmr.CateringName + "</td>");
        //    //    sb.Append("<td>" + Getzhouqi(cmr.StateDate, cmr.StopDate, RadionID) + " </td>");
        //    //    sb.Append("<td>" + Convert.ToDateTime(cmr.Back) + " </td>");
        //    //    sb.Append("<td>" + cmr.temp2 + "</td>");
        //    //    sb.Append("<td>" + AVGold(cmr, out Number) + "</td>");
        //    //    sb.Append("<td>" + Number + "</td>");
        //    //    sb.Append("</tr>");
        //    //}
        //    //return sb.ToString();
        //}

        
      
      
      
        public void Getload_Group()
        {
            Catering_Rules.T_Recipes crr = new Catering_Rules.T_Recipes();
            Catering_Model.E_Recipes cmr = crr.GetModel(Convert.ToInt32(HFshipuid.Value));
            Catering_Rules.GroupCatering crgc = new Catering_Rules.GroupCatering();
            Catering_Model.GroupCatering cmgc = crgc.GetModel(cmr.GroupID);
            Catering_Rules.ClassInfo crci = new Catering_Rules.ClassInfo();
            Catering_Model.ClassInfo cmci = crci.GetModel(cmgc.ClaassID);

            this.lbName.Text = cmgc.GCName;
            this.lblzhouqi.Text = cmr.StateDate.ToShortDateString() + "至" + cmr.StopDate.ToShortDateString();
            this.lblClass.Text = cmci.CName;
            this.lblNumber.Text = (cmgc.WNumber = cmgc.MNumber).ToString();
            voc.DropDownListDataBind_zhou(this.Dr_zhoulist, cmr.StateDate, cmr.StopDate);
        }
        public void Getload_Group(string[] strs)
        {
            string str_group = Session["Group"] as string;
            Catering_Rules.GroupCatering crgc = new Catering_Rules.GroupCatering();
            Catering_Model.GroupCatering cmgc = crgc.GetModel(Convert.ToInt32(str_group.Replace("'", "").Replace("'", "")));
            Catering_Rules.ClassInfo crci = new Catering_Rules.ClassInfo();
            Catering_Model.ClassInfo cmci = crci.GetModel(cmgc.ClaassID);

            this.lbName.Text = cmgc.GCName;
            this.lblzhouqi.Text = strs[0] + "至" + strs[strs.Length - 2];
            this.lblClass.Text = cmci.CName;
            this.lblNumber.Text = (cmgc.WNumber = cmgc.MNumber).ToString();
        }
        public void Getload_Personal(string[] strs)
        {
            string str_Personal = Session["Personal"] as string;
            Catering_Rules.PersonalService crps = new Catering_Rules.PersonalService();
            Catering_Model.PersonalService cmpc = crps.GetModel(Convert.ToInt32(str_Personal.Replace("'", "").Replace("'", "")));
            Catering_Model.Group_tedian cmgt = new Catering_Rules.Group_tedian().GetModel(Convert.ToInt32(cmpc.temp2));
            Catering_Model.MealTypes cmmt = new Catering_Rules.MealTypes().GetModel(Convert.ToInt32(cmpc.MealTypeID));
            lbl_Renqun.Text = cmpc.CateringName;
            lbl_shijian.Text = strs[0] + "至" + strs[strs.Length - 2];
            lblshanshi.Text = cmmt.MealType;
            lblpeican.Text = cmgt.PName;
        }


        public void GetDataList()
        {

            string str_backurl = Session["backurl"] as string;

            string str_Personal = Session["Personal"] as string;
            string[] strs = str_backurl.Replace("'", "").Split(new char[] { '|', ' ' });
            if (strs.Length > 0)
            {
                string str = "MID=14";
                int i = Convert.ToInt32(this.Dr_zhoulist.Items[0].Value);
                DataTable dt = voc.GetshipuInfo(strs[i], str, RadionID);
                str_All = voc.Getshipu(strs[i], RadionID, dt);
                str_1 = voc.Getshipu(strs[i]);
                str_2 = voc.Getshipu(strs[i + 1]);
                str_3 = voc.Getshipu(strs[i + 2]);
                str_4 = voc.Getshipu(strs[i + 3]);
                str_5 = voc.Getshipu(strs[i + 4]);
                //修改
                switch (RadionID)
                {
                    case 6:
                        str_6 = voc.Getshipu(strs[i + 5]);
                        break;
                    case 7:
                        str_6 = voc.Getshipu(strs[i + 5]);
                        str_7 = voc.Getshipu(strs[i + 6]);
                        break;
                }
                //修改
               
            }

        }
        #region 按钮事件
        #region 选择第几周
        protected void Dr_zhoulist_SelectedIndexChanged(object sender, EventArgs e)
        {
            string str = "MID=14";
            if (Session["backurl"] != null)
            {
                string str_backurl = Session["backurl"] as string;
                string str_Personal = Session["Personal"] as string;
                string[] strs = str_backurl.Replace("'", "").Split(new char[] { '|', ' ' });
                if (strs.Length > 0)
                {

                    int i = Convert.ToInt32(this.Dr_zhoulist.SelectedValue) * RadionID;
                    DataTable dt = voc.GetshipuInfo(strs[i], str, RadionID);
                    str_All = voc.Getshipu(strs[i], RadionID, dt);
                    str_1 = voc.Getshipu(strs[i]);
                    str_2 = voc.Getshipu(strs[i + 1]);
                    str_3 = voc.Getshipu(strs[i + 2]);
                    str_4 = voc.Getshipu(strs[i + 3]);
                    str_5 = voc.Getshipu(strs[i + 4]);
                    //修改
                    switch (RadionID)
                    {
                        case 6:
                            str_6 = voc.Getshipu(strs[i + 5]);
                            break;
                        case 7:
                            str_6 = voc.Getshipu(strs[i + 5]);
                            str_7 = voc.Getshipu(strs[i + 6]);
                            break;
                    }
                    //修改
                }
            }
            if (HFshipuid.Value.Length > 0)
            {
                int i = Convert.ToInt32(this.Dr_zhoulist.SelectedValue) * 7;
                DateTime dtime = new Catering_Rules.T_Recipes().GetModel(Convert.ToInt32(HFshipuid.Value)).StateDate.AddDays(i);
                DataTable dt = voc.GetshipuInfo(dtime.ToShortDateString(), str, RadionID);
                str_All = voc.Getshipu(dtime.ToShortDateString(), RadionID, dt);
                str_1 = voc.Getshipu(dtime.ToShortDateString(), dt, RadionID);
                str_2 = voc.Getshipu(dtime.AddDays(1).ToShortDateString(), dt, RadionID);
                str_3 = voc.Getshipu(dtime.AddDays(2).ToShortDateString(), dt, RadionID);
                str_4 = voc.Getshipu(dtime.AddDays(3).ToShortDateString(), dt, RadionID);
                str_5 = voc.Getshipu(dtime.AddDays(4).ToShortDateString(), dt, RadionID);

                //修改
                switch (RadionID)
                {
                    case 6:
                        str_6 = voc.Getshipu(dtime.AddDays(5).ToShortDateString(), dt, RadionID);

                        break;
                    case 7:
                        str_6 = voc.Getshipu(dtime.AddDays(5).ToShortDateString(), dt, RadionID);
                        str_7 = voc.Getshipu(dtime.AddDays(6).ToShortDateString(), dt, RadionID);
                        break;
                }
                //修改

            }
        }
        #endregion
        #region 保存
        protected void but_Save_Click(object sender, EventArgs e)
        {
            List<Catering_Model.E_RecipeInformation> list = Session["RecipeInformation"] as List<Catering_Model.E_RecipeInformation>;
            Catering_Rules.T_RecipeInformation crri = new Catering_Rules.T_RecipeInformation();
            if (this.HFshipuid.Value != null && this.HFshipuid.Value.Length > 0)
            {
                Boolean bl = crri.DeleteList("MID=" + this.HFshipuid.Value);
                if (bl)
                {
                    if (list.Count > 0)
                    {
                        foreach (Catering_Model.E_RecipeInformation cmpi in list)
                        {
                            cmpi.MID = Convert.ToInt32(this.HFshipuid.Value);
                            int NoWeek = 0;
                            NoWeek = new Catering_Rules.T_RecipesWeek().GetNumber(cmpi.Date, cmpi.MID);
                            cmpi.temp1 = NoWeek.ToString();
                            crri.Add(cmpi);
                        }
                    }
                }
            }

        }
        #endregion
        #region 另存为
        protected void but_Saveas_Click(object sender, EventArgs e)
        {
            List<Catering_Model.E_RecipeInformation> list = Session["RecipeInformation"] as List<Catering_Model.E_RecipeInformation>;
            Catering_Rules.T_RecipeInformation crri = new Catering_Rules.T_RecipeInformation();
            Catering_Rules.T_Recipes crr = new Catering_Rules.T_Recipes();
            Catering_Model.E_Recipes cmr = new Catering_Model.E_Recipes();

            string str_group = string.Empty;
            if (Session["Group"] != null)
            {
                str_group = Session["Group"] as string;
            }
            else
            {
                str_group = HFshipuid.Value;
            }
            Catering_Rules.GroupCatering crgc = new Catering_Rules.GroupCatering();
            Catering_Model.GroupCatering cmgc = crgc.GetModel(Convert.ToInt32(str_group.Replace("'", "").Replace("'", "")));
            cmr.CateringName = cmgc.GCName;
            cmr.ClassID = cmgc.ClaassID;
            cmr.GroupID = Convert.ToInt32(str_group.Replace("'", "").Replace("'", ""));
            cmr.PID = 1;
            cmr.Number = cmgc.MNumber + cmgc.WNumber;
            cmr.AreaID = cmgc.AreaID;
            cmr.ClassIDs = cmgc.ClaassID;
            cmr.Back = DateTime.Now.ToShortDateString();
            cmr.temp1 = "1";
            cmr.temp2 = "1";
            string[] str = this.lblzhouqi.Text.Trim().Split(new char[] { '至', ' ' });
            cmr.StateDate = Convert.ToDateTime(str[0]);
            cmr.StopDate = Convert.ToDateTime(str[1]);
            cmr.EditPersonnelID = LoginPersonnel.id;
            cmr.EditTime = DateTime.Now;
            crr.Add(cmr);
            if (list.Count > 0)
            {
                foreach (Catering_Model.E_RecipeInformation cmpi in list)
                {
                    cmpi.MID = cmr.id;
                    int NoWeek = 0;
                    NoWeek = new Catering_Rules.T_RecipesWeek().GetNumber(cmpi.Date, cmpi.MID);
                    cmpi.temp1 = NoWeek.ToString();
                    crri.Add(cmpi);
                }
            }

        }
        #endregion
        #region 导入事件
        protected void but_input_Click(object sender, EventArgs e)
        {
            Catering.View_Operaction.Caipin_Manage_Operaction cmo = new View_Operaction.Caipin_Manage_Operaction();
            ArrayList list = new ArrayList();
            if (HFshipuid.Value.Length > 0)
            {
                Getload_Group();
                Catering_Model.E_Recipes cmr = new Catering_Rules.T_Recipes().GetModel(Convert.ToInt32(HFshipuid.Value));
                cmo.GetDataList(cmr.StateDate, list, RadionID, HFshipuid.Value);
                string str = "MID=" + HFshipuid.Value;
                DataTable dt = voc.GetshipuInfo(cmr.StateDate.ToShortDateString(), str, Convert.ToInt32(HFshipuid.Value));
                Session["RecipeInformation"] = null;
                Session["RecipeInformation"] = voc.GetTableToList(dt, cmr.StateDate);
                str_All = list[0].ToString();
                ViewState["caipunnow"] = list[0].ToString();
                str_1 = list[1].ToString();
                str_2 = list[2].ToString();
                str_3 = list[3].ToString();
                str_4 = list[4].ToString();
                str_5 = list[5].ToString();
                //修改
                switch (RadionID)
                {
                    case 6:
                        str_6 = list[6].ToString();
                        break;
                    case 7:
                        str_6 = list[6].ToString();
                        str_7 = list[7].ToString();
                        break;
                }
                //修改



            }
        }
        #endregion
        #region 当前食谱
        protected void but_now_shipu_Click(object sender, EventArgs e)
        {
            string[] str = this.lblzhouqi.Text.Trim().Split(new char[] { '至', ' ' });
            if (str.Length > 1)
            {
                DataTable dt = voc.GetshipuInfo(str[0], "MID = 1", RadionID);
                ViewState["caipunnow"] = voc.Getshipu(str[0], RadionID, dt);
                ViewState["caipunnowstat"] = "1--";

            }

        }
        #endregion
        #endregion
    }
}